package cn.iocoder.yudao.module.erp.dal.mysql.deppurchase;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.erp.dal.dataobject.deppurchase.DepPurchaseDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.erp.controller.admin.deppurchase.vo.*;
import org.apache.ibatis.annotations.Update;

/**
 * ERP 科室采购申请单 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface DepPurchaseMapper extends BaseMapperX<DepPurchaseDO> {

    default PageResult<DepPurchaseDO> selectPage(DepPurchasePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<DepPurchaseDO>()
                .eqIfPresent(DepPurchaseDO::getWarehouseId, reqVO.getWarehouseId())
                .eqIfPresent(DepPurchaseDO::getDeptId, reqVO.getDeptId())
                .likeIfPresent(DepPurchaseDO::getOrderId, reqVO.getOrderId())
                .likeIfPresent(DepPurchaseDO::getIntegrateId, reqVO.getIntegrateId())
                .eqIfPresent(DepPurchaseDO::getRemark, reqVO.getRemark())
                .eqIfPresent(DepPurchaseDO::getStatus, reqVO.getStatus())
                .eqIfPresent(DepPurchaseDO::getProcessInstanceId, reqVO.getProcessInstanceId())
                .eqIfPresent(DepPurchaseDO::getCreator, reqVO.getCreator())
                .inIfPresent(DepPurchaseDO::getProcessInstanceId, reqVO.getProcessInstanceIds())
                .betweenIfPresent(DepPurchaseDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(DepPurchaseDO::getCreateTime));
    }

    default List<DepPurchaseDO> getDepPurchaseDOByIntegraId(String  integraId){
        return  selectList(DepPurchaseDO::getIntegrateId,integraId);
    }

    @Update("  update erp_dep_purchase set status = 1 , integrate_id = #{integraId}  where status = 0 and process_instance_id is not null ")
    void updateStatus(String integraId);

    @Update("  update erp_dep_purchase set status = #{status}  where integrate_id = #{integraId} ")
    void updateStatusByIntegraId(String integraId, Integer status);
}